<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Photo
 *
 * @property int $id
 * @property int $plan_id 拍摄计划id
 * @property int $user_id 用户id
 * @property string $path 图片地址
 * @property string $retouch_path 精修图地址
 * @property string $description 描述
 * @property int $retouch 是否需要精修
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read array $diff_img
 * @property-read mixed $path_url
 * @property-read mixed $retouch_path_url
 * @method static \Illuminate\Database\Eloquent\Builder|Photo newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Photo newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Photo query()
 * @method static \Illuminate\Database\Eloquent\Builder|Photo whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Photo whereDescription($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Photo whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Photo wherePath($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Photo wherePlanId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Photo whereRetouch($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Photo whereRetouchPath($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Photo whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Photo whereUserId($value)
 * @mixin \Eloquent
 */
class Photo extends Model
{
    protected $fillable = ['plan_id', 'user_id', 'path', 'retouch_path', 'description', 'retouch'];

    protected $appends = ['path_url', 'retouch_path_url', 'diff_img'];

    protected $casts = [
        'retouch' => 'bool'
    ];

    public function getPathUrlAttribute()
    {
        if (empty($this->attributes['path'])) {
            return '';
        }
        return url('storage/' . $this->attributes['path']);
    }

    public function getRetouchPathUrlAttribute()
    {
        if (empty($this->attributes['retouch_path'])) {
            return '';
        }
        return url('storage/' . $this->attributes['retouch_path']);
    }

    public function getDiffImgAttribute(): array
    {
        return array_filter([$this->path_url, $this->retouch_path_url]);
    }
}
